// xc/components/addr/location/label.js
var locationhelper = require('../../../sys/locationhelper')
Component({
  options: {
    addGlobalClass: true,
    multipleSlots: true
  },
  /**
   * 组件的属性列表
   */
  properties: {
    location:Object
  },

  /**
   * 组件的初始数据
   */
  data: {
    locationaddr: null,
    locationaddrtxt:"定位中...",
  },
  ready: function () { 

 
    this.locationaddrfunc();
    },
  /**
   * 组件的方法列表
   */
  methods: {
   
    updatedata(){
      var app = getApp();
      if (app.globalData.locationaddr&&app.globalData.locationaddr.status!=-1) {
        this.setData({ locationaddr: app.globalData.locationaddr,locationaddrtxt: app.globalData.locationaddr.addrinfo })
      }
    },
    locationaddrfunc() {
      console.log("xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx")
  
      var app = getApp();
  
      if (app.globalData.locationaddr&&app.globalData.locationaddr.status!=-1) {
     
        this.setData({ locationaddr: app.globalData.locationaddr,locationaddrtxt: app.globalData.locationaddr.addrinfo })
        this.triggerEvent("aftergetaddr",app.globalData.locationaddr)
      }
      else {
        var that = this;
   
        locationhelper.getcity().then(function (item) {
      
         
          // app.globalData.locationaddr=item;
          app.globalData.locationaddrtxt=item['message']

          console.log("ddddddddddddddddddd")
          console.log(item)

          if(item["status"]==-1){
           
            that.setData({ locationaddr: item,locationaddrtxt:item["message"] })
            that.triggerEvent("aftergetaddr",item)

          }
          else
          {
            that.triggerEvent("aftergetaddr",item.locationaddr)
            
            that.setData({ locationaddr: item.locationaddr,locationaddrtxt: item.locationaddr.addrinfo})
          }  
        })
      }
    },
  }
})
